/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.CapEntityManager.teste;

import br.com.CapEntityManager.Estado5;
import br.com.CapEntityManager.Governador5;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author egberto
 */
public class AdicionaGovernadorEstado {
    
    public static void main(String args[]){
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("default");
        EntityManager manager = factory.createEntityManager();
        
        manager.getTransaction().begin();
        
        Governador5 governador = new Governador5();
        governador.setNome("Jose da silva");
        
        Estado5 estado =  new Estado5();
        estado.setNome("São Paulo");
        
        governador.setEstado(estado);
        estado.setGovernador(governador);
        
        manager.persist(estado);
        manager.persist(governador);
        
        manager.getTransaction().commit();
        
        manager.close();
        factory.close();
    }
    
}
